#include "headfiles.h"

using namespace std;

int negateNum(int a) {
    int d = (a >= 0) ? -1 : 1;
    int negate = 0;

    while (a != 0) {
        a += d;
        negate += d;
    }

    return negate;
}

int minusNum(int a, int b) {
    int minus_b = negateNum(b);
    return (a + minus_b);
}

int absNum(int a) {
    int abs_num;
    if (a >= 0) {
        abs_num = a;
    }
    else {
        abs_num = negateNum(a);
    }

    return abs_num;
}

int multiNum(int a, int b) {
    int d_a = (a >= 0) ? 1 : -1;
    int d_b = (b >= 0) ? 1 : -1;

    int abs_a = absNum(a);
    int abs_b = absNum(b);

    int mult_num = 0;
    int i = 0;
    if (d_a == d_b) {
        for (i = 0; i != abs_b; i += 1) {
            mult_num += abs_a;
        }
    }
    else {
        for (i = 0; i != abs_b; i += 1) {
            mult_num -= abs_a;
        }
    }

    return mult_num;
}

int divideNum(int a, int b) {
    int d_a = (a >= 0) ? 1 : -1;
    int d_b = (b >= 0) ? 1 : -1;

    int abs_a = absNum(a);
    int abs_b = absNum(b);

    int i = 0;
    int res = 0;
    for (i = abs_b; i <= abs_a; i += abs_b) {
        res = res + 1;
    }

    if (d_a == d_b) {
        return res;
    }
    else {
        return negateNum(res);
    }
}

